 
function removePanel() {
    var tab = $('#tabs').tabs('getSelected');
    if (tab) {
        var index = $('#tabs').tabs('getTabIndex', tab);
        $('#tabs').tabs('close', index);
    }
}


function tabClose() {
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function () {
        var subtitle = $(this).children(".tabs-closable").text();
        $('#tabs').tabs('close', subtitle);
    })
    /*为选项卡绑定右键*/
    $(".tabs-inner").bind('contextmenu', function (e) {
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

        var subtitle = $(this).children(".tabs-closable").text();

        $('#mm').data("currtab", subtitle);
        $('#tabs').tabs('select', subtitle);
        return false;
    });
}

//绑定右键菜单事件
function tabCloseEven() {
    //刷新
    $('#mm-tabupdate').click(function () {
        var currTab = $('#tabs').tabs('getSelected');
        var url = $(currTab.panel('options').content).attr('src');
        if (url != undefined && currTab.panel('options').title != '首页') {
            $('#tabs').tabs('update', {
                tab: currTab,
                options: {
                    content: createFrame(url)
                }
            })
        }
    })
    //关闭当前
    $('#mm-tabclose').click(function () {
        var currtab_title = $('#mm').data("currtab");
        $('#tabs').tabs('close', currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function () {
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            if (t != '首页') {
                $('#tabs').tabs('close', t);
            }
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        var nextall = $('.tabs-selected').nextAll();
        if (prevall.length > 0) {
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        if (nextall.length > 0) {
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        return false;
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function () {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {
            //msgShow('系统提示','后边没有啦~~','error');
            alert('后边没有啦~~');
            return false;
        }
        nextall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            alert('到头了，前边没有啦~~');
            return false;
        }
        prevall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function () {
        $('#mm').menu('hide');
    })
}
function setCookie(name, value) {//两个参数，一个是cookie的名子，一个是值
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {//取cookies函数        
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}

function ShowException(data) {
    if (typeof (data) == 'object') {
        $('#PopWindowContet').html(data.responseText);
    }
    else {
        $('#PopWindowContet').html(data);
    }
    $('#PopWindow').window({
        width: 160,
        title:'异常',
        height: 6,
        modal: true
    });
    $('#PopWindow').window('open');
} 
 
 
 

function addPanel(id, title, src,_iconCls) {
    var panelwidth = $('#tabs').tabs('getTab', 0).width()-25; 
    var panelHeight = $('#tabs').tabs('getTab', 0).height()-25; 
    $('#tabs').tabs('add', {
        //iconCls: 'icon-edit'  ,
        title: title,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + src + '" style="width:'+panelwidth+'px;height:' + panelHeight + 'px;padding:10px;"></iframe>',
        closable: true
    });
    tabClose();
}

 
function baseGoUrl(url) {
    window.location.href = url;
}

function ShowPopWindow(_title, _url) {
    var _width=$(window).width() - 200;
    var _height=$(window).height() - 100; 
    $('#PopWindow').dialog({
        title:  _title, 
        width: _width,
        height: _height,
        closed: false,
        cache: false, 
        content: '<iframe scrolling="no" frameborder="0"  src="' + _url + '" style="width:100%;height:' + (_height -40)+ 'px"; overflow:hidden"></iframe>',
        modal: true
    });
} 
 

function  ShowPopWindowUrl(id, title, url, w_width, w_height) {
    var _width = 720;
    var _height = $(window).height()*0.8 ;  
    if (w_width != undefined) {
        _width = w_width;
        if (w_width && (''+w_width).indexOf('.') > 0) {
            _width = $(window).width() * parseFloat(w_width);
        }
    }
    if (w_height != undefined) {
        _height = w_height;
        if (w_height && (''+w_height).indexOf('.') > 0) {
            _height = $(window).height() * parseFloat(w_height);
        }
    }

    $('#PopWindow').dialog({
        title:  title,
        //iconCls: 'icon-edit'   ,
        width: _width,
        height: _height,
        closed: false,
        cache: false,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + url + '" style="width:100%;height:99%";margin:10px;"></iframe>',
        modal: true
    });
}

 
function ClosePopWindow() {
    $('#PopWindow').dialog({
        closed: true,
        content: ' a'
    });

}

function InintChart(_divid,   _title, _memo, _xtitle) {
    var i=0;
    var _xname=[];
    var _data=[];
    for(i=0;i<12;i++){
        _xname[i]= (i+1)+'月';
        _data[i]= parseInt(  Math.random()*10000);
    }

    $('#'+_divid).highcharts({
        chart: {
            type: 'column',
            margin: 75,
            options3d: {
                enabled: true,
                alpha: 10,
                beta: 25,
                depth: 70,
                viewDistance: 100,      // 视图距离，它对于计算角度影响在柱图和散列图非常重要。此值不能用于3D的饼图
                frame: {                // Frame框架，3D图包含柱的面板，我们以X ,Y，Z的坐标系来理解，X轴与 Z轴所形成
                    // 的面为bottom，Y轴与Z轴所形成的面为side，X轴与Y轴所形成的面为back，bottom、
                    // side、back的属性一样，其中size为感官理解的厚度，color为面板颜色
                    bottom: {
                        size: 10
                    },
                    side: {
                        size: 1,
                        color: 'transparent'
                    },
                    back: {
                        size: 1,
                        color: 'transparent'
                    }
                }
            },
        },
        title: {
            text: _title
        },
        subtitle: {
            text: _memo
        },
        plotOptions: {
            column: {
                depth: 25
            }
        },
        xAxis: {
            categories: _xname
        },
        yAxis: {
            title: {
                text: null
            }
        },
        series: [{
            name: _xtitle,
            data: _data
        }]
    });
} 

function navonclick(id,title,url) {
	    	addPanel(id,title ,url);
	    	//ShowPopWindowUrl(id,text ,url, WINDOWWIDTH, WINDOWHEIGHT);
}

function inintNav3(obj){ 
	var id=$(obj).attr('id').trim();
    var ul3obj=$('#nav3_'+id);
    $('.nav_3').addClass('displaynone');
    if(ul3obj && ul3obj.html() && ul3obj.html().length>5){
        ul3obj.removeClass('displaynone');
        return;
    }
    getmenuslist(id,function (navlist) {
        var htmlstr='';
        //后台获取下级菜单
        var i=0,j;
        htmlstr +='<ul class="nav_3" id="nav3_'+id+'"> ';
        for(i=0;i<navlist.length;i++){
            var item =navlist[i];
            htmlstr +='<li  id="'+item.menuCode.trim()+'" onclick="navonclick(\''+item.menuCode.trim()+'\',\''+item.menuName+'\',\''+item.menuUrl+'\')""> <span style="background-image: url('+item.menuIcon+')">&nbsp;</span><label>'+item.menuName+'</label></li> ';

        }
        htmlstr +='</ul>';
        $(obj).after(htmlstr);
    });
}

function inintNav2(obja){
	var id=$(obja).attr('id').trim();
	var title=$(obja).html(); 
    var htmlstr='';
    $('.expbtn').children('label').html(title);
    var i=0,j;
    getmenuslist(id,function (navlist) {
        for(i=0;i<navlist.length;i++){
            var item =navlist[i];
            htmlstr +='<a class="nav_2" id="'+item.menuCode.trim()+'" ';
            if(item.menuUrl==null || item.menuUrl=='null' || item.menuUrl.length  <16  ){
                htmlstr +='  onclick="inintNav3(this)" ';
            }else{
                htmlstr +=' onclick="navonclick(\''+item.menuCode.trim()+'\',\''+item.menuName+'\',\''+item.menuUrl+'\')" ';
            }

            htmlstr +='  > ';
            htmlstr +='<span style="background-image: url('+item.menuIcon+')">&nbsp;</span> ';
            htmlstr +=item.menuName+' </a>';

        }
        $('#navlist_2').html(htmlstr);
    });
}

function  getmenuslist(_parentMenuCode,callback) {
    var url ='/contest18/mgr/sysMenus/list';
    var data={
        "reqBody": {
            "areaCode": "ZZZZ",
            "menuCode": "GZWX",
            "parentMenuCode": _parentMenuCode
        },
        "reqHead": {
            "currPage": 1,
            "pageSize": 100
        }
    };
    Onluy.ajax.postData(url,data, function (data) {
        if(data.rspCode !=0)return;
        var navlist=data.rspData.list;
        callback(navlist);
    },function (result) {
        $.messager.alert('获取菜单异常', data.msgresult );
    } );
}

var navlist=[];
function init () {

    getmenuslist('SYS',function (navlist) {
        console.log("----------------navlist:"+ JSON.stringify(navlist))
        var i=0,navhtml='';
        for( i=0;i< navlist.length;i++){
            var nav=navlist[i];
            navhtml+='<div class="navroot" id="'+nav.menuCode+'" onclick="inintNav2(this)"> '+nav.menuName +'</div>';
        }
        $('.navroothead').after(navhtml);

    });


    $(".navroot:first").click();
}


$(function () {
    var cssstr = getQueryStringByName('theme'); 
    tabCloseEven(); 
    init ();
    $('#tabs').tabs({
         tabPosition:'left' ,       
        border: false
    });
    InintChart('chart_home','业务发展报表','最近12个月','张三');
    InintChart('chart_mobile','发展佣金报表','最近12个月','张三');

    $('#londing').window('close');
});
 